package com.cjm.one.goods.apps;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.common.utils.AuthCustomerContextHolder;
import com.cjm.one.goods.service.GoodsBrowseHistoryService;
import com.cjm.one.model.goods.entity.GoodsBrowseHistory;
import com.cjm.one.model.goods.vo.GoodsSkuBrowseHistoryVo;
import com.cjm.one.model.goods.vo.GoodsSkuVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/app/goods/browse/history")
@Tag(name = "商品浏览历史", description = "商品浏览历史")
public class AppGoodsBrowseHistoryController
{
    @Resource
    private GoodsBrowseHistoryService goodsBrowseHistoryService;

    @GetMapping("/add")
    @Operation(summary = "添加商品浏览历史")
    public Result<Boolean> add(@RequestParam("skuId") Long skuId)
    {
        Long customerId = AuthCustomerContextHolder.getAuthContextCustomer().getId();
        return Result.ok(goodsBrowseHistoryService.addGoodsBrowseHistory(customerId, skuId));
    }
    @DeleteMapping("/deleteBatch")
    @Operation(summary = "删除商品浏览历史")
    public Result<Boolean> deleteBatch(@RequestParam("ids") Long[] ids)
    {
        Long id = AuthCustomerContextHolder.getAuthContextCustomer().getId();
        return Result.ok(goodsBrowseHistoryService.deleteBatchGoodsBrowseHistoryByIds(ids, id));
    }
    @GetMapping("/list")
    @Operation(summary = "查询商品浏览历史")
    public Result<Page<GoodsSkuVo>> list(@RequestParam("current") Integer current,
                                         @RequestParam("size") Integer size)
    {
        Long id = AuthCustomerContextHolder.getAuthContextCustomer().getId();
        return Result.ok(goodsBrowseHistoryService.listGoodsBrowseHistoryByPage(id, current, size));
    }




}
